import type {
  User,
  Values,
  CodeType,
  UserInfo,
  PatientList,
  Patient
} from '@/types/user'
import { request } from '@/utils/request'

// 和用户相关的请求封装在这里 便于以后复用
export const loginByPassword = (values: Values) =>
  request<User>('/login/password', 'POST', values)

// getCode('13211112222', 'login')  用于登录
// getCode('13211112222', 'register')  用于注册
// getCode('123', 'bindMobile')
export const getCode = (mobile: string, type: CodeType) =>
  request<{ code: string }>('/code', 'get', {
    mobile: mobile,
    type: type
  })

// 短信登录
export const loginByMobile = (mobile: string, code: string) =>
  request<User>('/login', 'POST', { mobile, code })

// 获取用户信息 渲染个人中心
export const getUserInfo = () => request<UserInfo>('/patient/myUser')

// 获取列表
export const getPatientList = () => request<PatientList>('/patient/mylist')

// 添加患者信息
export const addPatient = (patient: Patient) =>
  request('/patient/add', 'POST', patient)

// 编辑患者
export const editPatient = ({
  id,
  idCard,
  name,
  gender,
  defaultFlag
}: Patient) => {
  return request('/patient/update', 'PUT', {
    id,
    idCard,
    name,
    gender,
    defaultFlag
  })
}

// 删除患者信息
export const delPatient = (id: string) =>
  request(`/patient/del/${id}`, 'DELETE')

// 封装一个用户未读消息数量的接口
export const getUnReadMsgCount = () => {
  return request<number>('/patient/message/unRead/all')
}
